import { dateFormat, dayDiff } from '@/utils/formatDate.js'

export default {
  data() {
    return {
      info: null, // 询价单信息
      biddingList: [], // 报价列表
      remainder: '', //剩余时间
      bidText: '暂无报价信息', // 暂无报价
      pageLoading: false, //初始化加载效果
    }
  },
  computed: {
    statusIcon() {
      return this.$store.state.accessory.statusIcon
    },
    status() {
      return this.$store.state.accessory.status
    },
    quality() {
      return this.$store.state.accessory.quality
    },
    formatName() {
      if (this.info.trueName) {
        return (
          this.info.trueName.slice(0, 1) +
          '*'.repeat(this.info.trueName.length - 1)
        )
      }
      return ''
    },
    formatPhone() {
      if (this.info.store_Phone) {
        return this.info.store_Phone.replace(/(.{3}).*(.{4})/, '$1****$2')
      }
      return ''
    },
    storeId() {
      return this.$store.state.userInfoDetail.store.storeId
    },
  },
  onLoad(e) {
    this.getInfo(e.id)
    this.getInquiryBidding(e.id)
    this.addCarPartBrowseNumber(e.id)
  },
  methods: {
    dateFormat,
    dayDiff,

    //获取订单信息
    getInfo(id) {
      this.$api.accessory
        .getInquiryInfo({
          id: id,
        })
        .then((res) => {
          this.info = res.data
          this.remainder = this.dayDiff(this.info.effective_Time)
          this.pageLoading = true
        })
        .catch((e) => {
          console.log(e)
          this.pageLoading = true
        })
    },

    // 获取报价列表
    getInquiryBidding(id) {
      this.$api.accessory
        .getInquiryBidding({
          id,
        })
        .then((res) => {
          console.log(res)
          if (res.data.length) {
            this.biddingList = res.data
            this.bidText = '没有更多报价了哦'
          }
        })
        .catch((e) => {
          console.log(e)
        })
    },

    addCarPartBrowseNumber(id) {
      const version = uni.getSystemInfoSync().system + ''
      this.$api.accessory
        .addCarPartBrowseNumber({
          id: id,
          system: 1,
          platform: 1,
          module: 1,
          version,
        })
        .then((res) => {
          console.log(res)
        })
        .catch((e) => {
          console.log(e)
        })
    },

    Iwantaquote() {
      uni.navigateTo({
        url: '/pages_findAccessory/submitQuote/submitQuote?id=' + this.info.id,
      })
    },

    //图片处理
    handdleImg(imgStr) {
      if (imgStr) {
        return JSON.parse(imgStr)
      }
    },
  },
}
